package com.los.rabbitmq.utils;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @program: rabbitmq
 * @description: rabbitmq工具类
 * @author: Yujuan
 * @create: 2018-08-01 21:23
 **/
public class ConnectionUtils {
    /**
     * 获取mq连接
     * @return
     */
    public static Connection getConnection() throws IOException, TimeoutException {
        //定义一个连接工厂
        ConnectionFactory factory=new ConnectionFactory();

        //设置服务地址
        factory.setHost("127.0.0.1");
        //设置端口
        factory.setPort(5672);
        //vhost
        factory.setVirtualHost("/vhost_los");
        //用户名
        factory.setUsername("user_los");
        //密码
        factory.setPassword("los");
        return factory.newConnection();
    }

}
